{{!

  Copyright (c) Meta Platforms, Inc. and affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

}}
{{#import "partials" as m_partials}}

{{#let partial field_required |field|}}
{{#pragma ignore-newlines}}
{{#if field.required?}}required
{{#else if field.optional?}}optional
{{#else if field.unqualified?}}opt-in-req-out
{{/if field.required?}}
{{/let partial}}

{{#let export partial render_struct |struct trailing_comma?| captures |m_partials field_required|}}
  "{{struct.name}}" : {
    "name" : "{{struct.name}}",
    {{#if (not (array.empty? struct.structured_annotations))}}
    "structured_annotations": {
      {{#partial m_partials.structured_annotations annotations=struct.structured_annotations}}
    },
    {{/if (not (array.empty? struct.structured_annotations))}}
    {{#if struct.docs?}}
    "docstring" : {{struct.docstring}},
    {{/if struct.docs?}}
    {{#if struct.fields?}}
    "fields" : {
      {{#each (array.enumerate struct.fields with_last=true) as |i field last_field?|}}
      "{{field.name}}" : {
        "name" : "{{field.name}}",
        {{#if (object.notnull? field.default_value)}}
        "default_value" : {{#partial m_partials.const_value value=field.default_value}},
        {{/if (object.notnull? field.default_value)}}
        {{#if field.docs?}}
        "docstring" : {{field.docstring}},
        {{/if field.docs?}}
        "key" : {{field.id}},
        "lineno" : {{field.lineno}},
        {{#if (not field.terse?)}}
        "required" : "{{#partial field_required field=field}}",
        {{/if (not field.terse?)}}
        "type" : {{#partial m_partials.type t=field.type}}
        {{#if (not (array.empty? field.structured_annotations))}},
        "structured_annotations": {
          {{#partial m_partials.structured_annotations annotations=field.structured_annotations}}
        }
        {{/if (not (array.empty? field.structured_annotations))}}
      }{{#if (not last_field?)}},{{/if}}
      {{/each}}
    },
    {{/if struct.fields?}}
    "is_exception" : {{#if struct.exception?}}true{{#else}}false{{/if}},
    "is_union" : {{#if struct.union?}}true{{#else}}false{{/if}},
    "lineno" : {{struct.lineno}}
  }{{#if trailing_comma?}},{{/if}}
{{/let partial}}
